package com.test.demo.io.nio;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.nio.channels.SocketChannel;

public class NIOSocketClient {
    public static void main(String[] args) throws IOException {
        SocketChannel socketChannel = SocketChannel.open();
        socketChannel.connect(new InetSocketAddress("localhost", 9000));
        System.out.println("客户端启动了");
        socketChannel.socket().getOutputStream().write("HelloServer".getBytes());
        socketChannel.socket().getOutputStream().flush();
        byte[] bytes = new byte[1024];
        socketChannel.socket().getInputStream().read(bytes);
        System.out.println("收到服务端发送"+new String(bytes));
        socketChannel.socket().close();
        socketChannel.close();
    }
}
